<?php
declare (strict_types = 1);

namespace app\api\model\v1;

use think\facade\Db;
use think\facade\Request;
use think\Model;

/**
 * @mixin \think\Model
 *
 * //采集日志+整改日志
 */
class OperateLog extends AppModel
{
    //

    /**
     * 类型(
     * 1.采集案件，
     * 2，采集审核案件，
     * 3，整改案件，
     * 4.审核整改案件，
     * 5.延期,
     * 6.延期审核，
     * 7.退回，
     * 8退回审核，
     * 9交办，
     * 10，交办审核)
     */
    const IS_COLLECT_ONE = 1;
    const IS_COLLECT_TWO = 2;
    const IS_COLLECT_THREE = 3;
    const IS_COLLECT_FOUR = 4;
    const IS_COLLECT_FIVE = 5;
    const IS_COLLECT_SEX = 6;
    const IS_COLLECT_SEVEN = 7;
    const IS_COLLECT_EiGHT = 8;
    const IS_COLLECT_NINE = 9;
    const IS_COLLECT_TEN = 10;



    /**
     * Created by PhpStorm.
     * User: 刘海龙
     * Date: 2022/1/2
     * Time: 19:12
     * @param $title
     * @param $content
     * @param $uid
     * @param $username
     * @return void
     * 采集日志
     */
    public static function operateRecord($title, $uid, $username,$collect_id,$type)
    {
        //获取url
        $url = substr(Request::url(), 0, 1500);
        //获取浏览器
        $useragent = Request::server('HTTP_USER_AGENT');
        $data = [
            'title' => $title,
            'url' => $url,
            'admin_id' => $uid,
            'collect_id' => $collect_id,
            'username' => $username,
            'useragent' => $useragent,
            'ip' => Request::ip(),
            'type'=>$type
        ];
        Db::name('operate_log')->save($data);
    }

    /**
     * @param $content
     * @User: 刘海龙
     * @Date: 2021/9/22
     * @Time: 12:02
     * @return array
     * 获取已屏蔽关键信息的数据
     */
    protected static function getPureContent($content)
    {
        if (!is_array($content)) {
            return $content;
        }
        foreach ($content as $index => &$item) {
            if (preg_match("/(password|salt|token)/i", $index)) {
                $item = "***";
            } else {
                if (is_array($item)) {
                    $item = self::getPureContent($item);
                }
            }
        }
        return $content;
    }
}
